class Visitor < ActiveRecord::Base

  has_and_belongs_to_many :events
  belongs_to :person

  def attend(event)
    self.events.push(event)
  end

  def hidden_email
    if !self.email.blank?
      hidden_email = ""
      length = self.email.length
      second_half = self.email[self.email.index("@")-1, self.email.length]
      hidden_email << self.email[0,1]
      length = length - 1
      chars_first_half = length - second_half.length
      chars_first_half.times do
        hidden_email << "*"
      end
      return hidden_email << second_half
    else
      return ""
    end
  end

  def hidden_phone
    if !self.phone.blank?
      hidden_phone = ""
      hidden_phone << self.phone[0,4]
      last_3 = self.phone[self.phone.length-3, self.phone.length]
      3.times do
        hidden_phone << "*"
      end
      hidden_phone << "-"
      hidden_phone << "*"
      return hidden_phone << last_3
    else
      return ""
    end
  end

end
